package com.thread.thread10;

public class ConnThreadLocal {

	public static ThreadLocal<String> threadLocal = new ThreadLocal<>();
	
	public void setTh(String str) {
		threadLocal.set(str);
	}
	public void getTh() {
		System.out.println(Thread.currentThread().getName() + " =  " + this.threadLocal.get());
	}
	
    public static void main(String[] args) throws InterruptedException {
		
		final ConnThreadLocal ct = new ConnThreadLocal();
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				ct.setTh("张三");
				ct.getTh();
			}
		}, "t1");
		
		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					ct.getTh();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}, "t2");
		
		t1.start();
		t2.start();
    }
}
